/*
 * User: user
 * Date: 15/02/2008
 * Time: 11:38:01
 */
package org.conann.instrument;

import javassist.CtClass;
import javassist.CtMethod;
import org.conann.metadata.scanning.ClassScanner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
import java.security.ProtectionDomain;

public class ComponentInitializerFileTransformer implements ClassFileTransformer {

    private final ClassScanner classScanner = new ClassScanner();
    private static final Logger log = LoggerFactory.getLogger(ComponentInitializerFileTransformer.class);

    public byte[] transform(ClassLoader loader, String classNameAsPath, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
        String className = classNameAsPath.replaceAll("/", ".");
        if (className.startsWith("conann")) {
            log.debug("Examining " + className);
            CtClass ctClass = CtUtil.getCtClass(className);
            if (CtUtil.isComponent(ctClass)) {
                log.debug("Loaded class " + ctClass.getName());
                for (CtMethod ctMethod : ctClass.getMethods()) {
                    if (ctMethod.getAvailableAnnotations().length > 0) {
                        System.out.println("");
                    }
                }
            }
        }
        return classfileBuffer;
    }
}